package com.yuwei.play.mvi

import androidx.lifecycle.viewModelScope
import com.yuwei.common.mvi.BaseViewModel
import com.yuwei.database.RoomDBUtils.getFavVideoDao
import kotlinx.coroutines.launch

class PlayViewModel : BaseViewModel<PlayApiService, PlayIntent>() {
    override fun handleIntent(intent: PlayIntent) {
        viewModelScope.launch {
            when (intent) {
                is PlayIntent.getVideoRecommend ->{
                    httpRequest(apiService.getVideoRecommend(intent.page,intent.pagesize),"getMovieRecommend")
                }
                is PlayIntent.getVideoComment ->{
                    httpRequest(apiService.getVideoComment(intent.datatype,intent.itemid),"getVideoComment")
                }
                is PlayIntent.sendComment ->{
                    httpRequest(apiService.sendComment(intent.sendCommentBody),"sendComment")
                }
                is PlayIntent.replyComment ->{
                    httpRequest(apiService.reply(intent.replyBody),"reComment")
                }
                is PlayIntent.commentDelete -> {
                    httpRequest(apiService.commentDelete(intent.id),"commentDelete")
                }
                is PlayIntent.replyDelete -> {
                    httpRequest(apiService.replyDelete(intent.id),"replyDelete")
                }
                is PlayIntent.getBullet ->{
                    httpRequest(apiService.getBullet(intent.datatype,intent.itemid),"getBullet")
                }
                is PlayIntent.insertFav ->{
                    roomRequest({getFavVideoDao().insert(intent.favVideoEntity)},"insertFav")
                }
                is PlayIntent.updateFav ->{
                    roomRequest({getFavVideoDao().update(intent.favVideoEntity)},"updateFav")
                }
                is PlayIntent.selecteByVideoId ->{
                    roomRequest({getFavVideoDao().getFavById(intent.videoId)},"selectByVideoId")
                }
            }
        }
    }
}